//app.js
var api = require('/config/api.js');
App({
  onLaunch: function() {
    var that = this;
    this.globalData.sysinfo = business.getSystemInfoSync();
  },
  businessLogin: function() {
    var that = this;
    return new Promise(function(resolve, reject) {
      business.login({
        success: function(res) {
          console.log("code:" + res.code);
          var code = res.code;
          business.request({
            url: api.BUSINESSLogin,
            method: 'get',
            data: { code: code },
            success: function(res) {
              console.log("businesslogin:" + JSON.stringify(res.data));
              resolve(res.data.data);
            },
            fail: function(err) {
              console.log("fail");
              reject(err);
            }
          })
        }
      })
    });
  },
  getModel: function() {
    return this.globalData.sysinfo["model"]
  },
  getBusinessVersion: function() {
    return this.globalData.sysinfo["version"]
  },
  getSystem: function() {
    return this.globalData.sysinfo["system"]
  },
  getPlatform: function() {
    return this.globalData.sysinfo["platform"]
  },
  getSDKVersion: function() {
    return this.globalData.sysinfo["SDKVersion"]
  },
  toastTips: function(txt) {
    business.showToast({ title: txt })
  },
  toastTips1: function(txt, time) {
    business.showToast({ title: txt, duration: time })
  },
  toastTips2: function(txt) {
    business.showToast({ title: txt, icon: "loading" })
  },
  showModal: function(txt) {
    business.showModal({ title: '提示', content: txt, showCancel: false })
  },
  showModal1: function(txt) {
    business.showModal({ title: "提示", content: txt, showCancel: false, confirmText: "确定" })
  },
  showLoading: function(txt) {
    business.showLoading({ title: txt, mask: true });
  },
  isBlank: function(str) {
    if (Object.prototype.toString.call(str) === '[object Undefined]') {
      return true
    } else if (Object.prototype.toString.call(str) === '[object String]' || Object.prototype.toString.call(str) === '[object Array]') {
      return str.length == 0 ? true : false
    } else if (Object.prototype.toString.call(str) === '[object Object]') {
      return JSON.stringify(str) == '{}' ? true : false
    } else {
      return true
    }
  },
  globalData: {
    sysinfo: null,
    mobile: '',
    password: '',
    role: '',
    subjects: [],
    classes: [],
    schoolList: [],
    schoolName: '',
    log: '',
    openId: '',
    user: null
  }
})